<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/3
 * Time: 20:07
 */
namespace app\index\controller;
use think\Controller;
use think\Db;

class Company extends Controller
{
    public function index(){

    }

    //获取出版社信息
    public function getCompany(){

        $ret = Db::table('company')->select();
        if($ret){
            $this->success('获取成功','',$ret);
        }
        else{
            $this->error('获取失败');
        }

    }

    //添加出版社信息
    public function updateCompany(){

        $data['company_id'] = input('company_id');
        $data['company_name'] = input('company_name');
        $data['company_logo'] = input('company_logo');
        $data['company_url'] = input('company_url');

        $ret1 = Db::table('company')
            ->where('company_id','=',$data['company_id'])
            ->update($data);
        if($ret1){
            $this->success('修改成功');
        }
        else{
            $ret = Db::table('company')->insert($data);
            if($ret){
                $this->success('插入成功');
            }
            else{
                $this->error('插入失败');
            }
        }
    }

    //删除出版社信息
    public function delCompany(){
        $id = input('company_id');

        $ret = Db::table('company')->where('company_id')->delete();
        if($ret){
            $this->success('删除成功');
        }
        else{
            $this->error('删除失败');
        }

    }

}